View Javadoc
1 /* 2 Java Regular Expressions Plugin API 3 4 Copyright (C) 2002 Jose San Leandro Armend?riz 5 jsanleandro@yahoo.es 6 chousz@yahoo.com 7 8 This library is free software; you can redistribute it and/or 9 modify it under the terms of the GNU Lesser General Public 10 License as published by the Free Software Foundation; either 11 version 2.1 of the License, or (at your option) any later version. 12 13 This library is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 Lesser General Public License for more details. 17 18 You should have received a copy of the GNU Lesser General Public 19 License along with this library; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 22 Thanks to ACM S.L. for distributing this library under the LGPL license. 23 Contact info: jsr000@terra.es 24 Postal Address: c/Playa de Lagoa, 1 25 Urb. Valdecaba?as 26 Boadilla del monte 27 28660 Madrid 28 Spain 29 30 This library uses some external APIs. So far I haven't released such 31 APIs as projects themselves, but you should be able 32 to download them from the web page where you got this source code. 33 34 ****************************************************************************** 35 * 36 * Filename: $RCSfile: CompilerGNUAdapter.java,v $ 37 * 38 * Author: Jose San Leandro Armend?riz 39 * 40 * Description: GNU Regexp 1.1.4-specific compiler adapter. 41 * This class makes possible the use of GNU Regexp 1.1.4 42 * compilers inside this API. 43 * 44 * Last modified by: $Author: dev $ at $Date: 2002/09/27 08:27:13 $ 45 * 46 * File version: $Revision: 1.9 $ 47 * 48 * Project version: $Name: $ 49 * ("Name" means no concrete version has been checked out) 50 * 51 * Version: $Revision: 1.9 $ 52 * 53 * $Id: CompilerGNUAdapter.java,v 1.9 2002/09/27 08:27:13 dev Exp $ 54 * 55 */ 56 package org.acmsl.regexpplugin.gnuregexp; 57 58 /* 59 * Importing project-specific classes. 60 */ 61 import org.acmsl.regexpplugin.Compiler; 62 import org.acmsl.regexpplugin.Pattern; 63 import org.acmsl.regexpplugin.MalformedPatternException; 64 65 /* 66 * Importing some ACM classes. 67 */ 68 import org.acmsl.version.Version; 69 import org.acmsl.version.VersionFactory; 70 71 /* 72 * Importing GNU Regexp 1.1.4 classes. 73 */ 74 import gnu.regexp.RE; 75 import gnu.regexp.REException; 76 77 /*** 78 * GNU Regexp 1.1.4-specific compiler adapter. This class makes 79 * possible the use of GNU Regexp 1.1.4 compilers inside this API. 80 * @author <a href="mailto:jsanleandro@yahoo.es" 81 >Jose San Leandro Armend?riz</a> 82 * @version $Revision: 1.9 $ 83 */ 84 public class CompilerGNUAdapter 85 implements Compiler 86 { 87 /*** 88 * Case sensitiveness. 89 */ 90 private boolean m__bCaseSensitive; 91 92 /*** 93 * Multiline parsing. 94 */ 95 private boolean m__bMultiline; 96 97 /*** 98 * Compiles given regular expression and creates a Pattern object 99 * to apply such rule on concrete text contents. 100 * @param regexp the regular expression to compile. 101 * @return the Pattern associated to such regular expression. 102 * @param MalformedPatternException if given regexp is malformed. 103 */ 104 public Pattern compile(String regexp) 105 throws MalformedPatternException 106 { 107 org.acmsl.regexpplugin.Pattern result = null; 108 109 try 110 { 111 int t_iOptions = 0; 112 113 t_iOptions |= 114 (isCaseSensitive()) 115 ? 0 116 : RE.REG_ICASE; 117 118 t_iOptions |= 119 (isMultiline()) 120 ? RE.REG_MULTILINE 121 : 0; 122 123 RE t_RE; 124 125 if (t_iOptions == 0) 126 { 127 t_RE = new RE(regexp); 128 } 129 else 130 { 131 t_RE = new RE(regexp, t_iOptions); 132 } 133 134 result = new PatternGNUAdapter(t_RE); 135 } 136 catch (REException exception) 137 { 138 throw new MalformedPatternExceptionGNUAdapter(exception); 139 } 140 catch (IllegalArgumentException illegalArgumentException) 141 { 142 if (resetOptions()) 143 { 144 result = compile(regexp); 145 } 146 } 147 148 return result; 149 } 150 151 /*** 152 * Resets the compiler options. 153 * @return true if the options actually changed. 154 */ 155 private boolean resetOptions() 156 { 157 boolean result = false; 158 159 result = 160 ( (isCaseSensitive()) 161 || (isMultiline())); 162 163 if (result) 164 { 165 setCaseSensitive(false); 166 167 setMultiline(false); 168 } 169 170 return result; 171 } 172 173 /*** 174 * Sets whether the compiler should care about case sensitiveness 175 * or not. 176 * @param caseSensitive true for differentiate upper from lower case. 177 */ 178 public void setCaseSensitive(boolean caseSensitive) 179 { 180 m__bCaseSensitive = caseSensitive; 181 } 182 183 /*** 184 * Retrieves whether the compiler should care about case sensitiveness 185 * or not. 186 * @return true if upper from lower cases are processed differently. 187 */ 188 public boolean isCaseSensitive() 189 { 190 return m__bCaseSensitive; 191 } 192 193 /*** 194 * Sets whether the compiler should care about new line delimiters 195 * or not. 196 * @param multiline false for parsing each line at a time. 197 */ 198 public void setMultiline(boolean multiline) 199 { 200 m__bMultiline = multiline; 201 } 202 203 /*** 204 * Sets whether the compiler should care about new line delimiters 205 * or not. 206 * @return false if the engine parses each line one at a time. 207 */ 208 public boolean isMultiline() 209 { 210 return m__bMultiline; 211 } 212 213 /*** 214 * Concrete version object updated everytime it's checked-in in a CVS 215 * repository. 216 */ 217 public static final Version VERSION = 218 VersionFactory.createVersion("$Revision: 1.9 $"); 219 220 /*** 221 * Retrieves the current version of this object. 222 * @return the version object with such information. 223 */ 224 public Version getVersion() 225 { 226 return VERSION; 227 } 228 229 /*** 230 * Retrieves the current version of this class. 231 * @return the object with class version information. 232 */ 233 public static Version getClassVersion() 234 { 235 return VERSION; 236 } 237 }

This page was automatically generated by Maven